package repository

import (
	"github.com/astaxie/beego/orm"
	"pq/models"
)

type AreaRepository struct {}

func (ar *AreaRepository) GetProvinces() []orm.Params {
	var areas []orm.Params
	slave := models.GetSlaveDb()
	_, _ = slave.Raw("select area_code,parent_code,area_name from area where level=1 and parent_code='0' order by area_code asc").Values(&areas)
	return areas
}

func (ar *AreaRepository) GetCity(province string) []orm.Params {
	var areas []orm.Params
	slave := models.GetSlaveDb()
	_, _ = slave.Raw("select area_code,parent_code,area_name from area where level=2 and parent_code=? order by area_code asc",province).Values(&areas)
	return areas
}

func (ar *AreaRepository) GetProvinceWithCity() []orm.Params {
	var areas []orm.Params
	slave := models.GetSlaveDb()
	_, _ = slave.Raw("select area_code,parent_code,area_name from area where level < 3 order by area_code asc").Values(&areas)
	return areas
}

